package tree;

public class BinarySelect {
    public static void main(String[] args) {
        int arr[] = {1,2,3,4,5,6,7};
        int min = 0;
        int max = arr.length-1;
        int num = 8;
        System.out.println(extracted(arr, min, max, num));
    }

    private static int extracted(int[] arr, int min, int max, int num) {
        while (min <= max){
            int mid = (min + max)/2;
            if (num == arr[mid]){
                System.out.println(mid);
                return mid;
            }
            if (num < arr[mid]){
                max = mid-1;
            }else {
                min = mid+1;
            }
        }
        return -1;
    }
}
